﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="UoMDetailForm.aspx.cs" Inherits="FBKPI.Forms.UoMDetailForm" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#divBrowseUOM").hide();
            $("#divBrowseUOM").dialog({ autoOpen: false, width: 900, height: 300, modal: true, resizable: false });

            $('.date-picker').datepicker({
                changeMonth: true,
                changeYear: true,
                showYear: true,
                showButtonPanel: true,
                dateFormat: 'MM yy',
                onClose: function (dateText, inst) {
                    var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
                    var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
                    $(this).datepicker('setDate', new Date(year, month, 1));
                }
            });

            $("#btn_save").click(function () {
                var param = "?";
                var isActive = 'false';

                $('#form1 td input:checked').each(function () {
                    var $cb = $(this);
                    if ($cb.attr('id') == 'chk_active') {
                        isActive = 'true';
                    }
                });

                var listval = "";
                if ($("#txt_listvaluemonth").val() != '')
                    listval = $("#txt_listvaluemonth").val();
                else
                    listval = $("#txt_listvalue").val();

                param = param + "action=save";
                param = param + "&ID=" + $("#txt_id").val();
                param = param + "&Description=" + $("#txt_description").val();
                param = param + "&ListValue=" + listval;
                param = param + "&UoMType=" + $("#txt_uomtype").val();
                param = param + "&isActive=" + isActive;
                param = param + "&UOM=" + $("#txt_uomid").val();
                param = param + "&CurrUser=" + $("#txt_user").val();
                ProcessRequest("UoMDetailHandler.ashx" + param, "#divdetail", "#UoMDetailTable");
                return false;
            });


            $("#btn_delete").click(function () {
                if (confirm('Are you sure to delete this record?')) {
                    var param = "?";
                    param = param + "action=delete";
                    param = param + "&ID=" + $("#txt_id").val();
                    param = param + "&CurrUser=" + $("#txt_user").val();
                    ProcessRequest("UoMDetailHandler.ashx" + param, "#divdetail", "#UoMDetailTable");
                    return false;
                }
                return false;
            });

            $("#btn_BrowseUOM").click(function () {
                $("#divBrowseUOM").dialog("option", "title", '<span class="header-text">Select Unit Of Measure</span>');
                $("#divBrowseUOM").dialog("open");
                $('#uom').dataTable({
                    "oLanguage": {
                        "sZeroRecords": "No records to display",
                        "sSearch": "Search"
                    },
                    "bSort": false,
                    "bPaginate": true,
                    "bAutoWidth": true,
                    "bProcessing": true,
                    "bServerSide": true,
                    "bDestroy": true,
                    "bJQueryUI": true,
                    "sPaginationType": "full_numbers",
                    "bDeferRender": true,
                    "fnServerData": function (sSource, aoData, fnCallback) {
                        $.ajax({
                            "dataType": 'json',
                            "type": "GET",
                            "url": "../Serializer/UoMSerializer.ashx",
                            "data": aoData,
                            "success": fnCallback
                        });
                    },
                    "aoColumns": [
                        { "mData": "No" },
                        { "mData": "Description" },
                        { "mData": "Format" },
                        { "mData": "isActive" },
                        { "mData": "ID" },
                    ],
                    "aoColumnDefs":
                    [
                        { "fnRender":
                            function (oObj) {
                                return "<a href=\"#\" onclick=\"PickUOM('" + oObj.aData["ID"] + "','" + oObj.aData["Description"] + "', '" + oObj.aData["Format"] + "')\"><img src='../images/ok.png' /></a>";
                            },
                            "aTargets": [4]
                        },
                        { "sClass": "center", "aTargets": [0, 2, 3, 4] },
                        { "fnRender":
                            function (oObj) {
                                if (oObj.aData["isActive"] == 'True') {
                                    return "<img src='../images/check.png' />"
                                }
                                else {
                                    return "<img src='../images/cross.png' />"
                                }
                            },
                            "aTargets": [3]
                        }
                    ]
                });

                //mark selected row
                $('body').on("click", '#uom tbody tr', function () {
                    $('#uom tbody tr').removeClass("row_selected");
                    $(this).addClass("row_selected");
                });
                $(".dataTables_filter input").focus();
                return false;
            });

            PickUOM = function (UOMID, UOMDescription, UoMFormat) {
                if (UoMFormat.toString() == 'Month') {
                    $("#txt_listvaluemonth").show();
                    $("#txt_listvalue").hide();
                    $("#txt_listvaluemonth").val('');
                    $("#txt_listvalue").val('');
                }
                else {
                    $("#txt_listvaluemonth").hide();
                    $("#txt_listvalue").show();
                    $("#txt_listvaluemonth").val('');
                    $("#txt_listvalue").val('');
                }
                $("#txt_uom").val(UOMDescription);
                $("#txt_uomid").val(UOMID);
                $("#txt_uomtype").val(UoMFormat);
                $("#divBrowseUOM").dialog("close");
            }
        });
    </script>
    <style>
        .ui-datepicker-calendar {display: none;}
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div id="categorykpiformarea" class="ui-widget-content padding5px ui-corner-all">
            <table class="dialogTable">
                <tr>
                    <td width="140px">ID</td>
                    <td class="Separator">:</td>
                    <td><asp:TextBox ID="txt_id" runat="server" ReadOnly="true"></asp:TextBox></td>
                </tr>
                <tr>
                    <td>Description</td>
                    <td>:</td>
                    <td><asp:TextBox ID="txt_description" runat="server" class="longText mandatory"></asp:TextBox></td>
                </tr>
                <tr>
                    <td>Unit of Measure</td>
                    <td>:</td>
                    <td>
                        <asp:TextBox ID="txt_uom" runat="server" ReadOnly="true" class="longText mandatory"></asp:TextBox>
                        <button id="btn_BrowseUOM" class="ui-button ui-state-default">
                            <span class="ui-button ui-icon ui-icon-newwin"></span>
                        </button>
                        <input type="hidden" id="txt_uomid" runat="server" />
                    </td>
                </tr>
                <tr>
                    <td>List Value</td>
                    <td>:</td>
                    <td>
                        <asp:TextBox ID="txt_listvalue" runat="server" class="longText mandatory" ></asp:TextBox>
                        <asp:TextBox ID="txt_listvaluemonth" runat="server" class="mandatory date-picker" ReadOnly="true"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>UoM Type</td>
                    <td>:</td>
                    <td><asp:TextBox ID="txt_uomtype" runat="server" class="longText mandatory" ReadOnly="true"></asp:TextBox></td>
                </tr>
                <tr>
                    <td>is Active</td>
                    <td>:</td>
                    <td><asp:CheckBox ID="chk_active" Checked="true" runat="server" /></td>
                </tr>
            </table>
        </div>
        <br />
        <div id="AuditInformation" class="ui-widget-content padding5px ui-corner-all">
            <b style="margin-left:5px">Audit Information</b>
            <table class="dialogTable">
                <tr>
                    <td width="140px">Last Modified Date</td>
                    <td class="Separator">:</td>
                    <td><asp:TextBox ID="txt_lastmodifieddate" runat="server" ReadOnly="true"></asp:TextBox></td>
                </tr>
                <tr>
                    <td>Last Modified By</td>
                    <td>:</td>
                    <td><asp:TextBox ID="txt_lastmodifiedby" runat="server" ReadOnly="true"></asp:TextBox></td>
                </tr>
                <tr>
                    <td>Create Date</td>
                    <td>:</td>
                    <td><asp:TextBox ID="txt_createdate" runat="server" ReadOnly="true"></asp:TextBox></td>
                </tr>
                <tr>
                    <td>Create By</td>
                    <td>:</td>
                    <td><asp:TextBox ID="txt_createby" runat="server" ReadOnly="true"></asp:TextBox></td>
                </tr>
            </table>
        </div>
        <div id="divBrowseUOM" class="ui-widget-content padding5px ui-corner-all">
            <table cellpadding="0" cellspacing="0" border="0" class="display" id="uom">
                <thead>
                    <tr>
                        <th>
                            No
                        </th>
                        <th>
                            Description
                        </th>
                        <th>
                            Format
                        </th>
                        <th>
                            is Active
                        </th>
                        <th>
                        </th>
                    </tr>
                </thead>
                <tbody>
                </tbody>
            </table>
        </div>
        <br />
        <button id="btn_save" class="ui-button ui-corner-all ui-button ui-state-default ui-button-text-icon-primary" runat="server" name="btnSave">
            <span class="ui-button-icon-primary ui-icon ui-icon-check"></span>
            <label class="ui-button-text">
                Save</label>
        </button>

        <button id="btn_delete" class="ui-button ui-corner-all ui-button ui-state-default ui-button-text-icon-primary" runat="server">
            <span class="ui-button-icon-primary ui-icon ui-icon-closethick"></span>
            <label class="ui-button-text">
                Delete</label>
        </button>
    </form>
</body>
</html>
